#!/bin/bash
echo "脚本执行过程中需要输入sudo密码"
img_type_name=$(head -n 1 log1-img_type_name)
img_hardware_name=$(head -n 1 log2-img_hardware_name)
loop_num=$(head -n 4 log3-loopnum  | tail -n 1)
echo $loop_num
# 拷贝u-boot文件到镜像的p1、p2两个分区
if [ $img_hardware_name == "hifive-unmatched" ]
	then
	sudo dd if=/mnt/usr/lib/u-boot/sifive_hifive_unmatched_fu740/u-boot-spl.bin of=/dev/loop0p1 bs=4k 
	sudo dd if=/mnt/usr/lib/u-boot/sifive_hifive_unmatched_fu740/u-boot.itb of=/dev/loop0p2 bs=4k 
elif [ $img_hardware_name == "visionfive1" ]
	then
	echo " "
else
	echo "适用的硬件类型错误，请检查log2-img_hardware_name文件中内容,并重新执行该脚本"
	exit
fi
p3='p3'
p4='p4'
loop_nump3=$loop_num$p3
loop_nump4=$loop_num$p4
# 删除镜像中命令历史
sudo rm /mnt/root/.bash_history
sudo umount $loop_nump3
sudo umount $loop_nump4
# 取消设置循环设备
sudo losetup -d $loop_num
